#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QFile>
#include <QFileDialog>
#include <QDebug>
MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    connect(ui->actionopen,&QAction::triggered,this,&MainWindow::handle_open);
    connect(ui->action_save,&QAction::triggered,this,&MainWindow::handle_save);
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::handle_open()
{
    qDebug()<<"hhhhh";
    QString path=QFileDialog::getOpenFileName(this);
    QFile* f=new QFile(path);
    bool ret=f->open(QFile::ReadOnly);
    if(ret==false)
    {
        ui->statusbar->showMessage("错误");
        return;
    }
    QString s=f->readAll();
    qDebug()<<s;
    ui->plainTextEdit->setPlainText(s);
    f->close();
    delete  f;
}

void MainWindow::handle_save()
{
    QString path=QFileDialog::getSaveFileName(this);
    QFile f(path);
    f.open(QFile::WriteOnly);
    QString s=ui->plainTextEdit->toPlainText();
    f.write(s.toUtf8());
    f.close();
}

